package com.clps.designPatterns.chapter01.开闭原则;

/**
 * 开闭原则是编程的基础,最重要的设计原则,在代码的结构的设计时,应该考虑对扩展开放,对修改关闭,抽象思维搭建结构,具体实现扩展细节
 */
public class C01_BookPrice {
    public static void main(String[] args) {
        DiscountBook partBook = new DiscountBook("java", 100.00);
        System.out.println(partBook.getPrice());
    }
}

interface  Book{
    String getName();
    Double getPrice();
}

/**
 * 平价书籍
 */
class ParitBook implements  Book{
    private String name ;
    private Double price ;
    public ParitBook(String name, Double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Double getPrice() {
        return this.price;
    }
}

class  DiscountBook extends  ParitBook{

    public DiscountBook(String name, Double price) {
        super(name, price);
    }

    @Override
    public Double getPrice() {
        double oldPrice = super.getPrice();
        return  oldPrice * 0.8;
    }
}